﻿
/*

typedef struct _MEMORY_BASIC_INFORMATION {
  PVOID  BaseAddress;
  PVOID  AllocationBase;
  DWORD  AllocationProtect;
  WORD   PartitionId;
  SIZE_T RegionSize;
  DWORD  State;
  DWORD  Protect;
  DWORD  Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;

SIZE_T VirtualQuery(
  [in, optional] LPCVOID                   lpAddress,
  [out]          PMEMORY_BASIC_INFORMATION lpBuffer,
  [in]           SIZE_T                    dwLength
);
SIZE_T VirtualQueryEx(
  [in]           HANDLE                    hProcess,
  [in, optional] LPCVOID                   lpAddress,
  [out]          PMEMORY_BASIC_INFORMATION lpBuffer,
  [in]           SIZE_T                    dwLength
);

*/


#include<iostream>
#include<windows.h>

using namespace std;

int main(){
	
	DWORD processId;
	
	//cout << "processId:";
	//cin >> processId;
	
	processId = GetCurrentProcessId();
	
	cout << processId << endl;
	
	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,processId);
	
	if (hProcess == NULL) {
        std::cerr << "无法打开进程" << std::endl;
        return 1;
    }
	
	MEMORY_BASIC_INFORMATION mbi;
    DWORD_PTR address = 0;
	while (VirtualQueryEx(hProcess, (LPCVOID)address, &mbi, sizeof(mbi))) {
        std::cout << "区域起始地址: 0x" << std::hex << mbi.BaseAddress << std::endl;
        std::cout << "区域大小: 0x" << std::hex << mbi.RegionSize << std::endl;
        std::cout << "状态: " << (mbi.State == MEM_COMMIT? "已提交" : "空闲") << std::endl;

        address += mbi.RegionSize;
		
		
    }

    CloseHandle(hProcess);
	
	
	
	
	
	
	return 0;
}